{% extends "_base.html" %}

{% block main %}

<!--<script>-->
<!--  function  redirectHandle(xhr) {-->

<!--    var url = xhr.getResponseHeader("redirectUrl");-->
<!--    console.log("redirectUrl = " + url);-->

<!--    var enable = xhr.getResponseHeader("enableRedirect");-->

<!--    if((enable == "true") && (url != "")){-->
<!--      var win = window;-->
<!--      while(win != win.top){-->
<!--        win = win.top;-->
<!--      }-->
<!--      win.location.href = url;-->
<!--    }-->

<!--  }-->

<!--  $(function () {-->

<!--    $(document).ajaxComplete(function (event, xhr, settings) {-->
<!--      console.log("ajaxComplete  adffdafadsaf")-->
<!--      redirectHandle(xhr);-->
<!--    })-->
<!--  });-->


<!--    $(function () {-->
<!--        $('#signinForm').submit(function (e) {-->
<!--            e.preventDefault();-->
<!--            var data = {-->
<!--                accountName: $('#accountName').val(),-->
<!--                password: $('#password').val()-->
<!--            };-->
<!--            $.ajax({-->
<!--                type: 'post',-->
<!--                url: '/signin',-->
<!--                data: JSON.stringify(data),-->
<!--                success: function (resp) {-->
<!--                    if (resp.error!=null) {-->
<!--                        $('#error').text(resp.error);-->
<!--                    } else {-->
<!--                      alert("dd");-->
<!--                        // location.assign('www.google.cn');-->
<!--                        //location.assign("/");-->
<!--                        //location.replace("/");-->
<!--                        //window.location="/";-->
<!--                        //window.location.href="/";-->
<!--                    }-->
<!--                },-->
<!--                contentType: 'application/json',-->
<!--                dataType: 'json'-->
<!--            });-->
<!--        });-->
<!--    });-->
<!--</script>-->

<script>
  $(function () {
    $('#signinForm').submit(function (e) {
      e.preventDefault();
      var data = {
        accountName: $('#accountName').val(),
        password: $('#password').val()
      };
      $.ajax({
        type: 'POST',
        url: '/signin',
        data: JSON.stringify(data),
        success: function (resp) {
          if (resp.error) {
            $('#error').text(resp.error);
          } else {
            location.assign('/');
          }
        },
        contentType: 'application/json',
        dataType: 'json'
      });
    });
  });
</script>
<form id="signinForm">
    <div class="form-group">
        <p id="error" class="text-danger"></p>
    </div>
    <div class="form-group">
        <label>Email</label>
        <input id="accountName" type="email" class="form-control" placeholder="Email">
    </div>
    <div class="form-group">
        <label>Password</label>
        <input id="password" type="password" class="form-control" placeholder="Password">
    </div>
    <button type="submit" class="btn btn-outline-primary">Submit</button>
</form>

{% endblock %}
